<template>
  <div class="storeedit">
    <!-- 门店-对话框 -->
    <el-dialog
      :title="text"
      :visible.sync="storeEdit"
      width="50%">
      <el-form :model="StoreForm" ref="StoreForm" size="medium" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="门店编号:" prop="store_no">
              <el-input v-model="StoreForm.store_no" placeholder="门店编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="门店名称:" prop="store">
              <el-input v-model="StoreForm.store" placeholder="门店名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="门店类型:" prop="store_value">
              <el-select v-model="StoreForm.store_value" placeholder="选择门店类型" style="width: 100%;">
                <el-option
                v-for="item in storeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态:" prop="status">
              <el-radio-group v-model="StoreForm.status">
                <el-radio :label="0">已启用</el-radio>
                <el-radio :label="1">已禁用</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item prop="agent" label="所属上级">
              <el-select v-model="StoreForm.uper" filterable clearable placeholder="所属上级" style="width: 100%;">
                <el-option
                  v-for="item in upList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="agent" label="所属下级">
              <el-select v-model="StoreForm.lower" filterable clearable placeholder="所属下级" style="width: 100%;">
                <el-option
                  v-for="item in lowerList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人:" prop="contact">
              <el-input v-model="StoreForm.contact" placeholder="联系人名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机:" prop="phone">
              <el-input v-model="StoreForm.phone" placeholder="手机"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="应收款(元):" prop="s_receive">
              <el-input v-model="StoreForm.s_receive" placeholder="应收款"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="余额日期:" prop="balance_date">
              <el-date-picker
                v-model="StoreForm.balance_date"
                type="date"
                format="yyyy-MM-dd"
                placeholder="余额日期" style="width: 100%;">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="地址:" prop="address">
              <v-distpicker :province="StoreForm.province" :city="StoreForm.city" :area="StoreForm.area" @selected="selected"></v-distpicker>
            </el-form-item>
            <el-form-item prop="address_detail">
              <el-input v-model="StoreForm.address_detail" placeholder="地址详情,如4号楼2单元"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="save">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import VDistpicker from 'v-distpicker'
  export default {
    name: 'StoreEdit',
    components: { VDistpicker },
    props:{
      rows:{}
    },
    data() {
      return {
        text: '',
        storeEdit: false, //门店对话框
        StoreForm: {
          store_type: '',
          store_no: '',
          store: '',
          contact: '',
          uper: '',
          lower: '',
          phone: '',
          s_receive: '',
          balance_date: '',
          address: '',
          status: '',
          store_value: '',

          province: '',
          city: '',
          area: '',
          address_detail: ''
        },
        storeList: [
          {value: '0',label: '直属门店'},
          {value: '1',label: '虚拟门店'},
        ],
        upList: [
          {value: '0',label: '--'},
          {value: '1',label: '代理商1号'}
        ],
        lowerList: [
          {value: '0',label: '--'}
        ]
      }
    },
    created() {

    },
    methods:{
      //打开对话框
      openEdit() {
        this.text = "编辑门店"
        this.storeEdit = true;
        this.StoreForm = {
         store_type: this.rows.store_type,
         store_no: this.rows.store_no,
         store: this.rows.store,
         contact: this.rows.contact,
         uper: this.rows.uper,
         lower: this.rows.lower,
         phone: this.rows.phone,
         s_receive: this.rows.s_receive,
         balance_date: this.rows.balance_date,
         address: this.rows.address,
         status: this.rows.status,
         store_value: this.rows.store_value
        }
      },

      openAdd() {
        this.text = "新增门店"
        this.storeEdit = true;
      },

      close(){
        this.storeEdit = false;
        this.StoreForm = {
          store_type: '',
          store_no: '',
          store: '',
          contact: '',
          uper: '',
          lower: '',
          phone: '',
          s_receive: '',
          balance_date: '',
          address: '',
          status: '',
          store_value: ''
        }
      },

      // 省市区选择最后一项触发
      selected(data) {
      // 对象的遍历,添加到另一对象中
        for (var obj in data) {
          this.StoreForm[obj] = data[obj].value
        }
      },

      //保存
      save () {
        this.$refs['StoreForm'].validate(valid => {
          if (valid) {
            console.log('form',this.StoreForm)
            this.storeEdit = false;
            this.StoreForm = {
              store_type: '',
              store_no: '',
              store: '',
              contact: '',
              uper: '',
              lower: '',
              phone: '',
              s_receive: '',
              balance_date: '',
              address: '',
              status: '',
              store_value: ''
            }
            this.$message.success('保存成功')
          } else {
            this.$message.error('表单验证失败!')
          }
        })
      }

    }
  }
</script>

<style>
</style>
